# 作者：小七
# 2025年01月05日
import os


def use_rename():
    os.rename('file3.txt', 'file4.txt')


def use_dir_func():
    file_list = os.listdir('.')
    print(file_list)
    os.mkdir('dir2')
    os.mkdir('dir1')
    os.rmdir('dir2')
    print(os.getcwd())


def change_dir():
    print(os.getcwd())
    os.chdir('dir1')
    print(os.getcwd())


def scan_dir(current_path):
    file_list = os.listdir(current_path)
    for file in file_list:
        print(file)
        if os.path.isdir(file):
            scan_dir(file)


def scan_dir_w(current_path, width):
    file_list = os.listdir(current_path)
    for file in file_list:
        print(' ' * width, file)
        new_path = current_path + '/' + file
        if os.path.isdir(new_path):
            scan_dir_w(new_path, width + 4)


def use_stat(file_path):
    file_info = os.stat('file.txt')
    print('size{},uid{},mode{:x},mtime{}'.format(file_info.st_size, file_info.st_uid,
                                                 file_info.st_mode, file_info.st_mtime))


if __name__ == '__main__':
    # use_rename()
    # use_dir_func()
    # change_dir()
    # scan_dir('.')
    # scan_dir_w('.', 0)
    use_stat('file1')
